/*
 *  Equalizer.h
 *  MantuPlay
 *
 *  Created by Markus Sintonen on 1.11.2009.
 *  Copyright 2009 __MyCompanyName__. All rights reserved.
 *
 */

#include <cstring>
#include <MacTypes.h>

#ifndef _TAUDIOFILTEREQ_H_
#define _TAUDIOFILTEREQ_H_

#define NUMBER_OF_BANDS 6

class EqualizerSettings 
	{
	public:
		float freq[NUMBER_OF_BANDS];
		float eq[NUMBER_OF_BANDS];
		int lowdb, highdb;
		EqualizerSettings();
	};

class Equalizer
	{
	private:
		static const int AF_NCH=2;
		static const int KM=NUMBER_OF_BANDS;
		float wq[AF_NCH][KM][2];      // Circular buffer for W data
		float g[AF_NCH][KM];
		float a[KM][2];               // A weights
		float b[KM][2];               // B weights
		int K;
		static void bp2(float* a, float* b, double fc, double q);
		float equalize(const float *g, SInt16 in, unsigned int ci);
	public:
		Equalizer(const EqualizerSettings *cfg, double sampleRate);
		void reset(void) {
			memset(wq,0,sizeof(wq));
		}
		void process(SInt32 *samples, UInt32 numsamples, unsigned int nchannels);
	};

#endif